import { Injectable } from '@nestjs/common';
import { InjectModel } from '@nestjs/mongoose';
import { Model } from 'mongoose';
import { NavigationMenu } from 'src/types/navigation_menu.interface';

@Injectable()
export class NavigationMenuService {
  constructor(
    @InjectModel('NavigationMenu')
    private navigationMenuModel: Model<NavigationMenu>,
  ) {}
  async find(query): Promise<NavigationMenu[]> {
    return this.navigationMenuModel.find(query).exec();
  }
  async create(
    createNavigationMenuDTO: NavigationMenu | NavigationMenu[],
  ): Promise<NavigationMenu | NavigationMenu[]> {
    if (Array.isArray(createNavigationMenuDTO)) {
      return this.navigationMenuModel.insertMany(createNavigationMenuDTO);
    } else {
      return new this.navigationMenuModel(createNavigationMenuDTO).save();
    }
  }
}
